//
//  Adaptor.TabBarController.swift
//  Adaptor
//
//  Created by 蒋晨成 on 2021/12/23.
//

import Foundation
import UIKit

public extension Adaptor { enum TabBar {} }

private extension Adaptor.TabBar {
    static weak var tabBarController: UITabBarController?
}

public extension Adaptor.TabBar {
    static func register(tabBarController: UITabBarController?) {
        self.tabBarController = tabBarController
    }
}

public extension Adaptor.TabBar {
    static var safeAreaTop: CGFloat {
        tabBarController?.view.safeAreaInsets.top ?? 0
    }

    static var safeAreaBottom: CGFloat {
        tabBarController?.view.safeAreaInsets.bottom ?? 0
    }

    static var navigationBarHeight: CGFloat {
        guard let tabBarController = tabBarController else { return 0 }
        let navigationController = tabBarController.navigationController ?? (tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController)
        return safeAreaTop + (navigationController?.navigationBar.bounds.height ?? 0)
    }

    static var tabBarHeight: CGFloat {
        tabBarController?.tabBar.bounds.height ?? 0
    }
}
